<?php
/**
 * TryCatch
 *
 * Exception support.
 *
 * @author  Badrus Said <badrus.said@gmail.com>
 * @since   gop1.0
 */
final class gop_TryCatch extends gop_Base {
    public function execute(gop_Base $_caller = null) {
        $this->setCaller($_caller);
        $T = (is_array($this->tryBlock)) ? $this->tryBlock : array($this->tryBlock);
        $C = (is_array($this->catchBlock)) ? $this->catchBlock : array($this->catchBlock);
        $F = (isset($this->finallyBlock)) ? ((is_array($this->finallyBlock)) ? $this->finallyBlock : array($this->finallyBlock)) : null;
        try {
            foreach($T as $x) {
                $this->getContext()->getCallee($x)->execute($this);
                if ($this->_return) return;
            }
        } catch(Exception $e) {
            foreach($C as $x) {
                $this->getContext()->getCallee($x)->execute($this);
                if ($this->_return) return;
            }
        }
        if (!is_null($F)) {
        foreach($F as $x) {
            $this->getContext()->getCallee($x)->execute($this);
            if ($this->_return) return;
        }}
        $this->chainExec();
    }
}
?>